package minimips
import (
    "fmt"
    "dumpwave"
)

func dmem(
	executeDmemo	chan EXDM,
	data_in		chan int,
	data_out	chan int) {

	/*var dmem = [] int {
		0x00000000,
		0x11111111,
		0x22222222,
		0x33333333,
		0x44444444,
		0x55555555,
		0x66666666,
		0x77777777}*/
		
	var dmem = [] int {
		0x00000000,
		0x00000000,
		0x00000000,
		0x00000000,
		0x00000000,
		0x00000000,
		0x00000000,
		0x00000000}

	for{
		exdm := <- executeDmemo

		fmt.Println("[dmem] EXDM <-- EXECUTE:",exdm.read_write)
		switch exdm.read_write {
			case 1: //read
				fmt.Printf("[dmem] DMEM[%d] --> DECODE: 0x%x\n",exdm.addr & 0x07,dmem[exdm.addr & 0x07])
				dumpwave.Wave(1,"data_outRA")
				dumpwave.Wave(int(dmem[exdm.addr & 0x07]),"data_out")
				data_out <- dmem[exdm.addr & 0x07]
				dumpwave.Wave(0,"data_outRA")
			case 0: //write
				dumpwave.Wave(1,"data_inRA")
				dmem[exdm.addr & 0x07] =<- data_in
				dumpwave.Wave(dmem[exdm.addr & 0x07],"data_in")
				dumpwave.Wave(0,"data_inRA")
				fmt.Printf("[dmem] DMEM[%d] <-- DECODE: 0x%x\n",exdm.addr & 0x07,dmem[exdm.addr & 0x07])
		}
		fmt.Println("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tMEMORIA:      ",dmem)
	}
}